package com.ujiuye.demo.impl;

import com.ujiuye.demo.ManagerDao;
import com.ujiuye.entity.Manager;
import com.ujiuye.util.JdbcUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class ManagerDaoImpl implements ManagerDao {
    QueryRunner qr=JdbcUtil.getQr();
    public Manager login(String username, String password){
        Manager manager = null;
        String sql = "select * from login where username=? and password=?";
        try {
            manager = qr.query(sql, new BeanHandler<>(Manager.class), username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return manager;
    }
    public int register(String username, String password){
        int rows = 0;
        String sql = "insert into login(username,password) value(?,?)";
        try {
            rows = qr.update(sql, username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rows;
    }
}
